package com.mdx.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mdx.bean.DiseaseBean;
import com.mdx.service.IDiseaseService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 病害
 */
@RestController
@RequestMapping("disease")
public class DiseaseController {
    @Resource
    private IDiseaseService diseaseService;

    //显示所有病害信息
    @RequestMapping("/findAllDisease")
    public IPage<DiseaseBean> findAllWorm(@RequestParam(value = "pageNO", defaultValue = "1") int pageNO,
                                          @RequestParam(value = "pageSize", defaultValue = "3") int pageSize) {
        return diseaseService.findByNameSigns(pageNO,pageSize,null,null);
    }


    //添加新病害
    @RequestMapping("addDisease")
    public String addDisease(DiseaseBean diseaseBean) {
        diseaseService.save(diseaseBean);
        return "ok";
    }


    //查看详细信息
    @RequestMapping("findById")
    public DiseaseBean findById(int diseaseId) {
        return diseaseService.getById(diseaseId);
    }

    //模糊查询
    @RequestMapping("findByName")
    public IPage<DiseaseBean> findByName(@RequestParam(value = "pageNO", defaultValue = "1") int pageNO,
                                    @RequestParam(value = "pageSize", defaultValue = "3") int pageSize,
                                    String diseaseName, String onsetSigns) {
        return diseaseService.findByNameSigns(pageNO,pageSize,diseaseName,onsetSigns);
    }
}
